# -*- coding: utf-8 -*-
from datetime import datetime
import pandas as pd
import numpy as np

if __name__ == '__main__':
    date_list = [datetime(2018,1,1), datetime(2018,1,2), datetime(2018,1,3),
                 datetime(2018,1,4), datetime(2018,1,5), datetime(2018,1,6)]
    # date_list = [3, 4,5,
    #              6,7,8]
    # print date_list
    series = pd.Series(np.random.randn(6),date_list)
    print series
    print type(series.index)
    print "--------获取数据，通过索引位置------------------------"
    print series[0]
    print "--------获取数据，索引值------------------------"
    print series[datetime(2018, 1, 1)]
    print "--------获取数据，可以被解析的日期字符串------------------------"
    print series["2018-01-01"]
    print "--------获取数据,按照年份，月份索引 --------------------------------------------------------"
    print series["2018-01"]
    print "--------获取数据,切片操作 --------------------------------------------------------"
    print series["2018-01-01":"2018-01-03"]

    print
    print "----------------------------------"
    dates = pd.date_range("2018-01-01",
                          periods=5,
                          freq='W-SAT')
    dates2 = pd.date_range("2018-01-01",#起始日期
                          periods=5,#周期
                          freq='W-MON') # 频率，W按照周生成，MON周一  SAT  周六
    print dates
    print dates2
    print type(dates)
    print pd.Series(np.random.randn(5), index=dates)